public class MiGong {
	public static void main(String[] args){
		int row = 10;
		int col = 9;
		int[][] map = new int[row][col];

		for(int i = 0; i < row; i++){
			map[i][0] = 1;
			map[i][col - 1] = 1;
			if(i < col){
				map[0][i] = 1;
				map[row - 1][i] = 1;
			}
		}

		map[3][1] = 1;
		map[3][2] = 1;

		T t = new T();
		t.findWay(map,1,1,row,col);

		for(int[] s : map){
			for(int x : s){
				System.out.print(x + " ");
			}
			System.out.println();
		}
	}
}

class T {
	public boolean findWay(int[][] map,int i,int j,int row,int col){
		if(map[row - 2][col - 2] == 2){
			return true;
		}else{
		if(map[i][j] == 0){
			map[i][j] = 2;
			if(findWay(map,i + 1,j,row,col)){
				return true;
			}else if(findWay(map,i,j + 1,row,col)){
				return true;
			}else if(findWay(map,i - 1,j,row,col)){
				return true;
			}else if(findWay(map,i,j - 1,row,col)){
				return true;
			}else{
				map[i][j] = 3;
				return false;
			}
		}else{
			return false;
		}
	}
	}
}